package com.eningqu.aipen.ui.adapter;

import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.eningqu.aipen.demo.R;
import com.eningqu.aipen.demo.databinding.ItemVideoBinding;
import com.eningqu.aipen.ui.vedio.VideoDetailActivity;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.ui.StyledPlayerControlView;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import com.google.android.exoplayer2.util.Util;

import java.util.HashMap;
import java.util.List;

/**
 * Package:com.eningqu.aipen.ui.adapter
 * Author:starr
 * Time:11/26/2023 4:13 PM
 * Description:
 */
public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHolder> {

    List<Bitmap> list;

    public VideoAdapter(List<Bitmap> list){
        this.list=list;
    }

    @NonNull
    @Override
    public VideoViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ItemVideoBinding binding= DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.item_video,viewGroup,false);
        VideoViewHolder holder=new VideoViewHolder(binding.getRoot());
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull VideoViewHolder videoViewHolder, int i) {
        ItemVideoBinding binding=DataBindingUtil.getBinding(videoViewHolder.itemView);

        ImageView playerView=binding.videoView;

        playerView.setImageBitmap(list.get(i));//对应的ImageView赋值图片
        binding.videoView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                VideoDetailActivity.startAction(binding.getRoot().getContext());
            }
        });


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class VideoViewHolder extends RecyclerView.ViewHolder{

        public VideoViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }


}

